﻿#include "MachineHelper.h"

#pragma execution_character_set("utf-8")
MachineHelper::MachineHelper(QObject *parent):QObject(parent)
{
    qDebug() << "enter MachineHelper::MachineHelper()";
    m_NetMgr = new QNetworkConfigurationManager();
    connect(m_NetMgr,&QNetworkConfigurationManager::onlineStateChanged,this,[=](bool isOnline){
        qDebug() << "NetworkConfigurationManager::onlineStateChanged: " << isOnline << "previousOnlineState" << previousOnlineState;
        if(previousOnlineState != isOnline && isOnline){
            qDebug() << "sigNetOnlineStatusChanged, previousOnlineState:" << previousOnlineState << ",isOnline:" << isOnline;
            emit sigNetOnlineStatusChanged(isOnline);
        }
        previousOnlineState = isOnline;
    });
}

MachineHelper *MachineHelper::mMachineHelper = nullptr;

MachineHelper *MachineHelper::GetInstance()
{
    if(nullptr == mMachineHelper){
        mMachineHelper = new MachineHelper();
    }
    return mMachineHelper;
}


bool MachineHelper::getNetInterfaceOnlineStatus()
{
    return m_NetMgr->isOnline();
}

bool MachineHelper::getPreviousOnlineState()
{
    return previousOnlineState;
}
